//
//  TOSchoolViewController.m
//  X-Tribe
//
//  Created by Miss.Ou on 16/3/30.
//  Copyright © 2016年 Miss.Ou. All rights reserved.
//

#import "TOSchoolViewController.h"
#import "TOSchoolCollectionCell.h"
#import "TODetailViewController.h"

@interface TOSchoolViewController ()<UICollectionViewDelegateFlowLayout,UICollectionViewDataSource,UICollectionViewDelegate>

@property (nonatomic,strong)UICollectionView *collectionView;


@end

@implementation TOSchoolViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor blueColor];
    [self createCollectionView];

}

#pragma mark - createCollectionView
- (void)createCollectionView{
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.itemSize = CGSizeMake(SCREEN_WIDTH/2 - 15 * WIDTH, (529/2-30) * HEIGHT);
    flowLayout.minimumLineSpacing = 10 * WIDTH;
    flowLayout.minimumInteritemSpacing = 10 *WIDTH;
    flowLayout.sectionInset = UIEdgeInsetsMake(10 * WIDTH, 10 * HEIGHT, 10 * WIDTH, 10 * HEIGHT);
    
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 49-64) collectionViewLayout:flowLayout];
    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
    self.collectionView.backgroundColor = [UIColor colorWithRed:0.94 green:0.94 blue:0.96 alpha:1];
    [self.view addSubview:self.collectionView];
    
    [self.collectionView registerClass:[TOSchoolCollectionCell class] forCellWithReuseIdentifier:@"schoolCollectionCell"];
    
}

#pragma mark - collectionViewDelegate
//设置显示item个数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    
    return 20;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"schoolCollectionCell";
    TOSchoolCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
    cell.backgroundColor = [UIColor whiteColor];
    return cell;
}


//点击触发的方法
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    TODetailViewController *detailVC = [[TODetailViewController alloc] init];
    [self.navigationController pushViewController:detailVC animated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
